package com.rylan.controller;

import com.rylan.entity.Order;
import com.rylan.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author rylan
 * @description
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderRepository orderRepository;
    @PostMapping("/save")
    public void save(@RequestBody Order order){
        orderRepository.save(order);
    }

    @GetMapping("/findAllByUid/{uid}/{index}/{limit}")
    public List<Order> findAllByUid(@PathVariable("uid") long uid, @PathVariable("index") int index, @PathVariable("limit") int limit){
        return orderRepository.findAllByUid(uid, index, limit);
    }

    @GetMapping("/findAllByState/{state}/{index}/{limit}")
    public List<Order> findAllByState(@PathVariable("state") int state,@PathVariable("index") int index,@PathVariable("limit") int limit){
        return orderRepository.findAllByState(state,index,limit);
    }

    @PutMapping("/updateState/{id}/{state}/{aid}")
    public void updateState(@PathVariable("id") long id, @PathVariable("state") int state, @PathVariable("aid") long aid){
        orderRepository.updateState(id,aid,state);
    }
}
